<?php
session_start();
require_once("../config/include_tokyo.inc.php");
require_once("../class/Common_Function.php");
$commonFunction = new Common_Function();

//访问权限验证
$userRole = $_SESSION['user_role'];
if($userRole == 1 || $userRole == 7){
	//管理员+ 女装
}else{
	if($userRole > 0){
		$url = "../index.php?loginError=2";//没权限
	}else{
		$url = "../index.php?loginError=3";//没登录
	}	
	echo "<script language='javascript' type='text/javascript'>";
	echo "window.location.href='$url'";
	echo "</script>";
}


//更新订单内容
$doFlag = $_POST["doFlag"];
if($doFlag == "doUpdate"){
	$id = $_POST["id"];
	$_GET['id'] = $id;
	$validateFlag = true;
    $sqlError = "";

	$io_flag =  $_POST["io_flag"];
	$amount =  $_POST["amount"];
	$note =  $_POST["note"];	
	if(eregi("^[0-9]+$",$amount)){
		//是数字	
		if($io_flag){
			if($amount < 0){ //转为正数
				$amount = $amount*-1;
			}
			if($io_flag == 1 || $io_flag == 2 || $io_flag == 3 || $io_flag == 11){
				//收入为正
			}else{
				//支出为负
				$amount = $amount*-1;
			}
		}
		
	}else{
		$validateFlag = false;
		$sqlError = $sqlError."  金额只能是数字";
	}

	if($validateFlag){
		$sql = "update financial set io_flag = '".$io_flag."'";
		$sql = $sql.", amount= ".$amount;		
		$sql = $sql.", note='".$note."'";
		$sql = $sql."  where id=".$id;	
		$db->Execute($sql);	
	}else{
		echo $sqlError;
	}

	$db->Execute($sql);
}


//详情 
$id = $_GET['id'];
if($id == ""){
	//新增
}else{
	//编辑
	$sql = "SELECT * from financial where id=".$id;
	$result = $db->Execute($sql);
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!--Begin:head-->
<? $pageTitle = "单笔资金详情"; ?>
<?php include("../head.php"); ?>
<!--End:head-->


<body>
<?php include("../clothingMenu.php"); ?>


<form name="inputForm" action="../clothing/financialInput.php" method="post">
<div id="container" >	
<div class="grayTable">	
<h4>单笔资金详情:
<?php  if($doFlag == "doUpdate"){echo "更新成功!";}?>
</h4>
<table >
<thead>
	<tr>
		<th scope="col" width=90 >字段名称</th>
	    <th scope="col" >字段值</th>		
	</tr>
</thead>

<?php
if (!empty($result)) {
	$io_flag = $result->fields['io_flag'];
	$io_flag_1 = "";
	$io_flag_2 = "";
	$io_flag_3 = "";
	$io_flag_4 = "";
	$io_flag_5 = "";
	$io_flag_6 = "";
	$io_flag_7 = "";
	$io_flag_8 = "";
	$io_flag_9 = "";
	$io_flag_10 = "";
	$io_flag_11 = "";
	if($io_flag == 1){
		$io_flag_1 = "selected";
	}else if($io_flag == 1){
		$io_flag_1 = "selected";
	}else if($io_flag == 2){
		$io_flag_2 = "selected";
	}else if($io_flag == 3){
		$io_flag_3 = "selected";
	}else if($io_flag == 4){
		$io_flag_4 = "selected";
	}else if($io_flag == 5){
		$io_flag_5 = "selected";
	}else if($io_flag == 6){
		$io_flag_6 = "selected";
	}else if($io_flag == 7){
		$io_flag_7 = "selected";
	}else if($io_flag == 8){
		$io_flag_8 = "selected";
	}else if($io_flag == 9){
		$io_flag_9 = "selected";
	}else if($io_flag == 10){
		$io_flag_10 = "selected";
	}else if($io_flag == 11){
		$io_flag_11 = "selected";
	}


	$strTR = "";
	$strTR = $strTR."<tr ><td>ID</td>";
	$strTR = $strTR."<td>".$id."</td></tr>";
	$strTR = $strTR."<tr ><td>创建时间</td>";
	$strTR = $strTR."<td>".$result->fields['create_time']."</td></tr>";
	$strTR = $strTR."<tr ><td>资金流向</td>";
	$strTR = $strTR."<td>";
	$strTR = $strTR."<select name='io_flag' id='io_flag'>";
	$strTR = $strTR."<option value=1 ".$io_flag_1." >".$commonFunction->getIOFlagName(1)."</option>";
	$strTR = $strTR."<option value=2 ".$io_flag_2." >".$commonFunction->getIOFlagName(2)."</option>";
	$strTR = $strTR."<option value=3 ".$io_flag_3." >".$commonFunction->getIOFlagName(3)."</option>";
	$strTR = $strTR."<option value=11 ".$io_flag_11." >".$commonFunction->getIOFlagName(11)."</option>";
	$strTR = $strTR."<option value=4 ".$io_flag_4." >".$commonFunction->getIOFlagName(4)."</option>";
	$strTR = $strTR."<option value=5 ".$io_flag_5." >".$commonFunction->getIOFlagName(5)."</option>";
	$strTR = $strTR."<option value=6 ".$io_flag_6." >".$commonFunction->getIOFlagName(6)."</option>";
	$strTR = $strTR."<option value=7 ".$io_flag_7." >".$commonFunction->getIOFlagName(7)."</option>";
	$strTR = $strTR."<option value=8 ".$io_flag_8." >".$commonFunction->getIOFlagName(8)."</option>";
	$strTR = $strTR."<option value=9 ".$io_flag_9." >".$commonFunction->getIOFlagName(9)."</option>";
	$strTR = $strTR."<option value=10 ".$io_flag_10." >".$commonFunction->getIOFlagName(10)."</option>";
	$strTR = $strTR."</select>";
	$strTR = $strTR."</td></tr>";
	$strTR = $strTR."<tr ><td>金额</td>";
	$strTR = $strTR."<td><input type='text' name='amount' id='amount' value='".$result->fields['amount']."' size=20></td></tr>";
	$strTR = $strTR."<tr ><td>备注</td>";
	$strTR = $strTR."<td><input type='text' name='note' id='note' value='".$result->fields['note']."' size=50></td></tr>";
	$strTR = $strTR."<tr><td colspan=2 align=center>";
	$strTR = $strTR."<input type='button' value='保存' onclick='doUpdate(".$id.")'>";
	$strTR = $strTR."<input type='button' value='返回' onClick='toList()'>";
	$strTR = $strTR."</td></tr>";
	echo $strTR;
}

?>

</table>



</div>

<br><br>
<br><br>

</div><!--end container -->

<input type="hidden" name="doFlag" id="doFlag" >
<input type="hidden" name="id" id="id" >
</form>
</body>




</html>

<script>


function doUpdate(id){
	document.getElementById('doFlag').value = 'doUpdate';
	document.getElementById('id').value = id;
	document.inputForm.submit();
}


function toList(){
	window.location.href = "financialList.php";
}
</script>

